package cc.rengu.redp.bizimpl.csmc.controller;

import cc.rengu.igas.bomp.facade.BompManualAdjustAcctService;
import cc.rengu.redp.bizimpl.csmc.domain.ReconErrTxn;
import cc.rengu.redp.bizimpl.csmc.service.IReconErrTxnService;
import cc.rengu.redp.bizimpl.csmc.vo.ReconErrTxnVO;
import cc.rengu.redp.bizimpl.enums.PageOptFlagEnum;
import cc.rengu.redp.bizimpl.upmp.service.IUpmpBMchntBaseInfoService;
import cc.rengu.redp.bizimpl.upmp.service.IUpmpSysParamService;
import cc.rengu.redp.bizimpl.upmp.vo.UpmpUserInfoVO;
import cc.rengu.redp.bizimpl.utils.CommonUtils;
import cc.rengu.redp.common.annotation.Log;
import cc.rengu.redp.common.controller.BaseController;
import cc.rengu.redp.common.domain.QueryRequest;
import cc.rengu.redp.common.exception.RedpException;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


/**
 * @author guohaocong
 */
@Api(tags = "业务查询:对账不平:营销对账不平")
@RestController
@Slf4j
@RequestMapping("/admin/csmc/Marketing")
public class MarketingController extends BaseController {
    private long oprMenuId = 1;
    private String oprMenuName = "业务查询:对账不平:营销对账不平";
    private long chkMenuId = 2;
    private String chkMenuName = "业务查询:对账不平:营销对账不平";
    private String webNextUrl = "/admin/csmc/teReconerrTxn/edit";


    @Autowired
    private IReconErrTxnService reconErrTxnService;
    @Autowired
    private IUpmpBMchntBaseInfoService upmpBMchntBaseInfoService;
    @Autowired
    private IUpmpSysParamService upmpSysParamService;
    @Autowired(required = false)
    private BompManualAdjustAcctService bompManualAdjustAcctService;

    @Log("分页")
    @GetMapping("/findPage")
    public Map<String, Object> findPage(QueryRequest request, ReconErrTxn reconErrTxn) {
        return getDataTable(reconErrTxnService.SelectMarketingList(request, reconErrTxn));
    }

    @Log("添加")
    @PostMapping("/saveData")
    public void saveData(ReconErrTxnVO reconErrTxnVO) throws RedpException {
        String menuId;
        String flag = reconErrTxnVO.getOptFlag();
        if (PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(flag)) {
            menuId = String.valueOf(chkMenuId);
        } else {
            menuId = String.valueOf(oprMenuId);
        }
        reconErrTxnService.saveData(menuId, oprMenuName, reconErrTxnVO, webNextUrl, chkMenuName);
    }

    @Log("修改")
    @PostMapping("/updateData")
    public void updateData(ReconErrTxnVO reconErrTxnVO) throws RedpException {
        String primaryKey = reconErrTxnVO.getPrimaryKey();
        // 当前登录用户
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        String instId = reconErrTxnVO.getInstId();
        reconErrTxnService.manualAdjustment(bompManualAdjustAcctService, user, primaryKey, instId, upmpBMchntBaseInfoService.genMerOrder(instId));
    }

    @Log("查询数据")
    @GetMapping("/showData")
    public  Map<String, Object> showData(ReconErrTxnVO reconErrTxnVO) throws RedpException {
        return reconErrTxnService.showData(reconErrTxnVO);
    }
}
